package com.efuture.redis.findprovicedemo.web.servlet;

import com.efuture.redis.findprovicedemo.domian.Provice;
import com.efuture.redis.findprovicedemo.service.ProviceService;
import com.efuture.redis.findprovicedemo.service.impl.ProviceServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author ：赵山山
 * @description：TODO
 * @date ：2021/10/6 12:07 上午
 */
@WebServlet("/FindAllProviceServlet")
public class FindAllProviceServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        ProviceService proviceService = new ProviceServiceImpl();
//        List<Provice> allProvice = proviceService.findAllProvice();
//        //序列化json
//        ObjectMapper objectMapper = new ObjectMapper();
//        String value = objectMapper.writeValueAsString(allProvice);

        String value =  proviceService.findAllProviceForRedis();

        resp.setContentType("appliction/json;charset=utf-8");
        resp.getWriter().write(value.trim());
    }
}

